<!--
<script setup>

</script>

<template>
支付申请列表
</template>

<style scoped>

</style>--><script setup>
import { ref, reactive, defineComponent } from 'vue';
import { ElForm, ElInput, ElButton, ElSelect, ElOption, ElTable, ElTableColumn, ElDialog } from 'element-plus';
import { useRouter } from 'vue-router';

const router = useRouter();
const dialogVisible = ref(false);
const form = reactive({
  department: '',
  type: '',
  amount: '',
});
const types = ref(['加班补助', '出差报销', '其他']);
const expenses = ref([
  { department: '技术部', type: '加班补助', amount: '3462.23' },
  { department: '人事部', type: '出差报销', amount: '5000.00' },
  // 更多费用数据
]);

const rules = {
  department: [{ required: true, message: '部门为必填项', trigger: 'blur' }],
  type: [{ required: true, message: '费用类型为必填项', trigger: 'change' }],
  amount: [{ required: true, message: '金额为必填项', trigger: 'blur' }],
};

const submitApplication = () => {
  // 表单验证和提交逻辑
  console.log('提交的表单数据:', form);
  router.push('/account/butieman/pay');
};

const chooseType = (type) => {
  dialogVisible.value = true;
  router.push('/account/butieman/paylist')
};

const selectExpense = (expense) => {
  form.type = expense.type;
  form.amount = expense.amount;
};

const confirmSelection = () => {
  dialogVisible.value = false;
  submitApplication();
  router.push('/account/butieman/paylist')
};
</script>
<template>
  <div class="payment-application-form">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="部门" prop="department" required>
        <el-input v-model="form.department" placeholder="请输入部门"></el-input>
      </el-form-item>
      <el-form-item label="费用类型" prop="type" required>
        <el-select v-model="form.type" placeholder="请选择费用类型" @change="chooseType">
          <el-option v-for="type in types" :key="type" :label="type" :value="type"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="金额（小写）" prop="amount" required>
        <el-input v-model="form.amount" placeholder="请输入金额"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitApplication">提交</el-button>
      </el-form-item>
    </el-form>

    <el-dialog title="选择费用类型" v-model="dialogVisible">
      <el-table :data="expenses" @row-click="selectExpense">
        <el-table-column prop="department" label="部门"></el-table-column>
        <el-table-column prop="type" label="类型"></el-table-column>
        <el-table-column prop="amount" label="金额"></el-table-column>
      </el-table>
      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmSelection">确定</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<style scoped>
.payment-application-form {
  max-width: 600px;
  margin: 20px auto;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-button {
  display: block;
  margin: 20px auto;
}
</style>